﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;
using System.IO;

namespace DinhTam
{
    public partial class Banner : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
            //    banner();
                load();
            }
        }

        protected void load()
        {
            StringBuilder str=new StringBuilder();
            string path = System.Configuration.ConfigurationManager.AppSettings["Images_Path"];
            DataTable tb = new DataTable();
            tb = XLDL.XLDL.XLDaTa("select * from Banner where hien_thi='True' ORDER BY Ngay_Dang DESC");
            for (int i = 0; i < tb.Rows.Count; i++)
            {
                str.Append("<li>");
                if (tb.Rows[i]["link"].ToString() == "")
                {
                    str.Append("<img src='" + path + tb.Rows[i]["hinh_anh"].ToString() + "' title='' width='950px' alt='' border='0px'/>");
                }
                else
                {
                    str.Append("<a href='"+tb.Rows[i]["link"].ToString()+"'><img src='" + path + tb.Rows[i]["hinh_anh"].ToString() + "' title='' width='950px' alt='' border='0px'/></a>");
                }
                //<!--<div class="lof-main-item-desc" style="background:url('NewBanner/images/bg_trans.png');">
                //    <h3><a target="_parent" title="Newsflash 1" href="#Category-1">/ Newsflash 1 /</a> <i> — Monday, February 15, 2010 12:42</i></h3>
                //    <h2>Content of Newsflash 1</h2>
                //    <p>The one thing about a Web site, it always changes! Joomla! makes it easy to add Articles, content,...
                //    <a class="readmore" href="#">Read more </a>
                //    </p>
                // </div>-->
                str.Append("</li>");
            }
            lbl_load.Text=str.ToString();
            //////////////
            str = new StringBuilder();
            for (int i = 0; i < tb.Rows.Count; i++)
            {
                str.Append("<li><img src='" + path + tb.Rows[i]["hinh_anh"].ToString() + "' alt='' width='70px' height='25px'/></li>");
            }
            lbl_navigator.Text = str.ToString();
        }
        //protected void banner()
        //{
        //    try
        //    {
        //        StringBuilder str = new StringBuilder();
        //        string img = "";
        //        string all = "";
        //        string h = "";
        //        string t = "";
        //        string w = "";
        //        string path = System.Configuration.ConfigurationManager.AppSettings["Images_Path"];
        //        DataTable tb = new DataTable();
        //        tb = XLDL.XLDL.XLDaTa("select * from Banner where hien_thi='True' ORDER BY Ngay_Dang DESC");
        //        StreamReader f1 = new StreamReader(Server.MapPath("Js\\B.js"));
        //        StreamReader f2 = new StreamReader(Server.MapPath("Js\\W.js"));
        //        StreamReader f3 = new StreamReader(Server.MapPath("Js\\T.js"));

        //        h = f1.ReadToEnd();
        //        w = f2.ReadToEnd();
        //        t = f3.ReadToEnd();
        //        str.Append("<script type='text/javascript'>");
        //        str.Append("var firstreel=new reelslideshow_Banner({");
        //        str.Append("wrapperid: 'myreel',");

        //        if (tb.Rows.Count == 1)
        //        {
        //            img += "['" + path + tb.Rows[0]["Hinh_Anh"].ToString() + "','" + tb.Rows[0]["link"].ToString() + "','_parent'],";
        //            img += w;
        //        }
        //        else//if (tb.Rows.Count!= 0)
        //        {
        //            if (tb.Rows.Count == 0)
        //            {
        //                return;
        //            }
        //            for (int i = 0; i <= tb.Rows.Count - 1; i++)
        //            {
                       
        //                    img += "['" + path + tb.Rows[i]["Hinh_Anh"].ToString() + "','"+tb.Rows[i]["link"].ToString()+"','_parent'],";
        //                    img += w;
        //            }

        //        }
               
        //        img = img.Replace("'", "\"");
        //        img = img.Trim();
        //        img = img.Remove(img.Length - 1, 1);
        //        all = str.ToString() + h + img + t + "<div id='myreel'></div>";

        //        lbl_banner.Text = all;
        //        f1.Close();
        //        f2.Close();
        //        f3.Close();
        //    }
        //    catch { }

        //}
    }
}